<template>
    <base-breadcrumb :title="$route.meta.title">
        <!-- 安全问题整改管理 -->
        <div id="base-breadcrumb" style="position: relative; z-index: 1">
            <!-- 搜索 -->
            <searchData :searchData="searchArr" @search="search"></searchData>
            <!-- 表格 -->
            <a-card :bordered="false">
                <!-- <title-name title="安全问题整改与跟踪"></title-name> -->
                <!-- <a-button class="mb20" type="primary" @click="handleManage(2)">添加安全问题整改</a-button> -->
                <!-- 汇总 -->
                <collapseStatic
                    ref="collapseStatic"
                    :columnsSummary="columnsSummary"
                    :tabList="tabList"
                    :form="queryParam"
                    :switchSummary.sync="switchSummary"
                    :loadCount="loadCount"
                    :loadDataSummaryApi="api"
                    :closeWithNoArgs="true"
                >
                    <template #left="scoped">
                        <span
                            >安全整改数
                            <a
                                ><b>{{ scoped.data.total || 0 }}</b></a
                            >，</span
                        >
                        <span
                            >待整改
                            <a
                                ><b>{{ scoped.data.stayRectification || 0 }}</b></a
                            >，</span
                        >
                        <span
                            >整改中
                            <a
                                ><b>{{ scoped.data.rectificationIn || 0 }}</b></a
                            >，</span
                        >
                        <span
                            >待复查
                            <a
                                ><b>{{ scoped.data.stayReview || 0 }}</b></a
                            >，</span
                        >
                        <span
                            >复查通过
                            <a
                                ><b>{{ scoped.data.stayPass || 0 }}</b></a
                            >，</span
                        >
                        <span
                            >不合格不整改
                            <a
                                ><b>{{ scoped.data.unqualified || 0 }}</b></a
                            >，</span
                        >
                        <span
                            >超时未整改
                            <a
                                ><b>{{ scoped.data.overtime || 0 }}</b></a
                            >，</span
                        >
                        <span
                            >整改完成率
                            <a
                                ><b>{{ scoped.data.rectificationRate || '0%' }}</b></a
                            ></span
                        >
                    </template>
                </collapseStatic>
                <!-- 表格 -->
                <list-table
                    ref="table"
                    tableLayout="fixed"
                    size="default"
                    :rowKey="(record) => record.id"
                    :columns="columns"
                    :request="loadData"
                    :alert="true"
                    show-size-changer
                    show-quick-jumper
                    showPagination="auto"
                >
                    <span slot="sort" slot-scope="text, record, index">{{ index + 1 }}</span>

                    <span slot="rectificationStatus" slot-scope="text">
                        <status :text="text"></status>
                    </span>
                    <span slot="action" slot-scope="text, record">
                        <template>
                            <a @click="handleManage(0, record)">查看</a>
                            <!-- 当状态为待复查2时显示 -->
                            <!-- <template v-if="record.rectificationStatusId == 2">
                <a-divider type="vertical"></a-divider>
                <a @click="handleManage(1, record)">复查</a>
              </template> -->
                            <!-- <a-divider v-if="record.rectificationStatusId == 2" type="vertical"></a-divider>
              <a v-if="record.rectificationStatusId == 2" @click="handleManage(1, record)">复查</a> -->
                            <!-- <a-divider type="vertical"></a-divider>
                <a class="del_btn" @click="handleDelete(record)">删除</a>-->
                        </template>
                    </span>
                    <p slot="expandedRowRender" slot-scope="record" style="margin: 0">
                        问题描述：{{ record.problemRectificationDescription || '无' }}
                    </p>
                </list-table>
            </a-card>
        </div>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { problemRectification } from '@/api/quality/safe' // api
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import Selector from '@/components/Select/Selector'
import SelectProject from '@/components/Select/SelectProject' // 项目名称
import CollapseStatic from '@/views/quality/components/CollapseStatic' // 汇总
import status from './status'
const searchArr = [
    // 搜索框
    {
        name: '分公司',
        type: SelectSubCompany,
        valueKey: 'branchCompanyId',
    },
    // {
    //     name: '项目名称',
    //     type: SelectProject,
    //     valueKey: 'projectId',
    // },
    {
        name: '安全检查编号',
        value: 'checkNumber',
        type: 'input',
    },
    {
        name: '安全隐患',
        value: 'securityRisks',
        type: 'input',
    },
    {
        name: '检查类型',
        type: Selector,
        selectType: '0',
        attr: { code: '0' },
        valueKey: 'checkType',
    },
    {
        name: '复查人',
        value: 'reviewer',
        type: 'input',
    },
    {
        name: '检查时间',
        value: 'checkTime',
        type: 'dateRange',
        attr: {
            rangeFormat: ['checkTimeStart', 'checkTimeEnd'],
        },
    },
    {
        name: '整改状态',
        valueKey: 'rectificationStatus',
        type: Selector,
        selectType: '3',
    },
    {
        name: '整改期限',
        value: 'rectificationPeriod',
        type: 'dateRange',
        attr: {
            rangeFormat: ['rectificationPeriodStart', 'rectificationPeriodEnd'],
        },
    },
    {
        name: '整改单位',
        value: 'rectificationUnit',
        type: 'input',
    },
]
const columns = [
    {
        title: '序号',
        dataIndex: 'sort',
        scopedSlots: { customRender: 'sort' },
    },
    {
        title: '分公司',
        dataIndex: 'branchCompanyName',
    },
    {
        title: '项目名称',
        ellipsis: true,
        dataIndex: 'projectName',
    },
    {
        title: '安全检查编号',
        width: '120px',
        ellipsis: true,
        dataIndex: 'checkNumber',
    },
    {
        title: '安全隐患',
        ellipsis: true,
        dataIndex: 'securityRisks',
    },
    {
        title: '复查人',
        ellipsis: true,
        dataIndex: 'reviewer',
    },
    {
        title: '整改人',
        ellipsis: true,
        dataIndex: 'rectificationPeople',
    },
    {
        title: '整改单位',
        ellipsis: true,
        dataIndex: 'rectificationUnit',
    },
    {
        title: '检查类型',
        dataIndex: 'checkType',
    },
    {
        title: '整改期限',
        width: '115px',
        dataIndex: 'rectificationPeriod',
    },
    {
        title: '整改状态',
        width: '100px',
        dataIndex: 'rectificationStatus',
        scopedSlots: { customRender: 'rectificationStatus' },
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: '180px',
        align: 'center',
        fixed: 'right',
        scopedSlots: { customRender: 'action' },
    },
]
export default {
  name:'a'+ Date.now(),
    components: {
        STable,
        CollapseStatic,
        status,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            loadCount: 0,
            switchSummary: '0', // 统计标题
            api: problemRectification,
            tabList: [
                {
                    key: '0',
                    name: '按检查区域统计',
                },
                {
                    key: '1',
                    name: '按分包统计',
                },
                {
                    key: '2',
                    name: '按检查人',
                },
                {
                    key: '3',
                    name: '按整改人',
                },
                {
                    key: '4',
                    name: '按分公司',
                },
                {
                    key: '5',
                    name: '按项目',
                },
            ], // 汇总标题
            // 加载数据方法 必须为 Promise 对象
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                return problemRectification.getList(requestParameters).then((res) => {
                    return res
                })
            },
        }
    },
    computed: {
        // 汇总表头
        columnsSummary() {
            return [
                {
                    title: ['检查区域', '分包商', '检查人', '整改人', '分公司', '项目'][this.switchSummary],
                    dataIndex: 'name',
                    ellipsis: true,
                },
                {
                    title: '整改数',
                    dataIndex: 'total',
                    ellipsis: true,
                },
                {
                    title: '待整改数',
                    dataIndex: 'stayRectification',
                },
                {
                    title: '整改中',
                    dataIndex: 'rectificationIn'
                },
                {
                    title: '待复查',
                    dataIndex: 'stayReview',
                },
                {
                    title: '复查通过',
                    dataIndex: 'stayPass',
                },
                {
                    title: '不合格不整改',
                    dataIndex: 'unqualified',
                },
                {
                    title: '超时未整改',
                    dataIndex: 'overtime',
                },
                {
                    title: '整改率',
                    dataIndex: 'rectificationRate',
                },
            ]
        },
    },
    methods: {
        /**
         * 搜索
         */
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
            this.loadCount++
        },
        /**
         * 操作栏
         */
        handleManage(type, record) {
            this.$router.push({
                name: 'safeRecordInfo',
                query: {
                    id: record?.id,
                    checkType: '1',
                    manageType: '1',
                },
            })
        },
        /**
         * 删除记录
         */
        handleDelete(e) {
            let that = this
            that.$confirm({
                title: '温馨提示',
                content: '确认删除？',
                okText: '确认',
                cancelText: '关闭',
                onOk() {
                    return problemRectification.remove({ id: e.id }).then((res) => {
                        // if (res.data.code == 200) {
                        that.$message.success('删除成功！')
                        that.$refs.table.loadData()
                        // } else {
                        //   that.$message.warning('删除失败！')
                        // }
                    })
                },
            })
        },
    },
}
</script>


